package com.mo.core.hessianProxyFactory;

import com.caucho.hessian.client.HessianProxyFactory;
import com.mo.core.util.JwtTokenUtil;

public class MoHessianProxyFactory extends HessianProxyFactory {

	private String md5Key;

	private String secret;
	
	private Long expiration;

	public void setExpiration(Long expiration) {
		this.expiration = expiration;
	}

	public void setMd5Key(String md5Key) {
		this.md5Key = md5Key;
	}

	public void setSecret(String secret) {
		this.secret = secret;
	}

	@Override
	public String getBasicAuth() {
		final String randomKey = JwtTokenUtil.getRandomKey();
		final String token = JwtTokenUtil.generateToken(
				"", 
				randomKey,
				this.md5Key, 
				this.secret, 
				(this.expiration!=null&&this.expiration!=0L)?this.expiration:100L);
//		System.out.println(token);
		// (authRequest.getUserName(), randomKey);
		return "Bearer " + token;
	}

}
